<?php		
	session_start();
	
	require_once("../../include_dao.php");			

	$flag = false;
	
	if(isset($_SESSION['dtoUser'])){
		unset($_SESSION['dtoUser']);
	}
	
	if(isset($_SESSION['dtoPartner'])){
		unset($_SESSION['dtoPartner']);			
	}
	
	if(isset($_POST['login'])){ 		
		if(isset($_POST['password'])){
			$user = $_POST['login']; 
			$pass = $_POST['password'];			
			if( $user != '' and $pass != ''){
				$flag = true;
			}			
		}
	}
	
	if($flag){ 
					
		$dtoUser = new User();
		try{
			// Validacion de Informacion 
		 $dtoUser = DAOFactory::getUserDAO()->loaduser($user,$pass);
				 
		 $id = $dtoUser->pKUser;
		 $dtoPartner = DAOFactory::getPartnerDAO()->load($id);
		 
		 if(isset($dtoUser->pKUser)){
				$_SESSION['dtoUser']	= serialize($dtoUser);
				$_SESSION['dtoPartner']	= serialize($dtoPartner);
				
				header( 'Location: ../../index.php');
		 } else	{			 
			header( 'Location: ../../login.php?err=11'); 
		 }
		 
		}
		catch (Exception $e){					
			header( 'Location: ../../login.php?err=11');
		}
	}
	else{
		header( 'Location: ../../login.php?err=11');
	}

?>
